package demo.huodongbaoming.client;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 校园活动报名服务客户端降级实现
 * 当校园活动报名服务不可用时，提供降级响应
 */
@Component
public class CampusActivityClientFallback implements CampusActivityClient {

    @Override
    public List<Map<String, Object>> getAllActivities() {
        List<Map<String, Object>> fallbackList = new ArrayList<>();
        Map<String, Object> fallbackResponse = new HashMap<>();
        fallbackResponse.put("id", -1);
        fallbackResponse.put("title", "暂无活动信息");
        fallbackResponse.put("description", "校园活动服务暂时不可用，请稍后再试");
        fallbackResponse.put("startTime", "未知");
        fallbackResponse.put("status", "服务不可用");
        fallbackResponse.put("isFallback", true);
        fallbackList.add(fallbackResponse);
        return fallbackList;
    }

    @Override
    public Map<String, Object> getActivityById(Long id) {
        Map<String, Object> fallbackResponse = new HashMap<>();
        fallbackResponse.put("id", id);
        fallbackResponse.put("title", "未知活动");
        fallbackResponse.put("description", "活动详情暂时无法获取");
        fallbackResponse.put("startTime", "未知");
        fallbackResponse.put("location", "未知");
        fallbackResponse.put("status", "服务不可用");
        fallbackResponse.put("message", "校园活动服务暂时不可用，请稍后再试");
        fallbackResponse.put("isFallback", true);
        return fallbackResponse;
    }

    @Override
    public List<Map<String, Object>> getActivitiesByUser(Long userId) {
        List<Map<String, Object>> fallbackList = new ArrayList<>();
        Map<String, Object> fallbackResponse = new HashMap<>();
        fallbackResponse.put("id", -1);
        fallbackResponse.put("title", "暂无报名活动");
        fallbackResponse.put("description", "您的报名活动信息暂时无法获取");
        fallbackResponse.put("startTime", "未知");
        fallbackResponse.put("status", "服务不可用");
        fallbackResponse.put("userId", userId);
        fallbackResponse.put("message", "校园活动服务暂时不可用，请稍后再试");
        fallbackResponse.put("isFallback", true);
        fallbackList.add(fallbackResponse);
        return fallbackList;
    }

    @Override
    public List<Map<String, Object>> getActivitiesByCategory(Long categoryId) {
        List<Map<String, Object>> fallbackList = new ArrayList<>();
        Map<String, Object> fallbackResponse = new HashMap<>();
        fallbackResponse.put("id", -1);
        fallbackResponse.put("title", "暂无分类活动");
        fallbackResponse.put("description", "该分类的活动信息暂时无法获取");
        fallbackResponse.put("startTime", "未知");
        fallbackResponse.put("status", "服务不可用");
        fallbackResponse.put("categoryId", categoryId);
        fallbackResponse.put("message", "校园活动服务暂时不可用，请稍后再试");
        fallbackResponse.put("isFallback", true);
        fallbackList.add(fallbackResponse);
        return fallbackList;
    }

    @Override
    public Map<String, Object> registerForActivity(Long activityId, Long userId) {
        Map<String, Object> fallbackResponse = new HashMap<>();
        fallbackResponse.put("activityId", activityId);
        fallbackResponse.put("userId", userId);
        fallbackResponse.put("status", "失败");
        fallbackResponse.put("message", "校园活动服务暂时不可用，无法完成报名，请稍后再试");
        fallbackResponse.put("isFallback", true);
        return fallbackResponse;
    }

    @Override
    public Map<String, Object> cancelRegistration(Long activityId, Long userId) {
        Map<String, Object> fallbackResponse = new HashMap<>();
        fallbackResponse.put("activityId", activityId);
        fallbackResponse.put("userId", userId);
        fallbackResponse.put("status", "失败");
        fallbackResponse.put("message", "校园活动服务暂时不可用，无法取消报名，请稍后再试");
        fallbackResponse.put("isFallback", true);
        return fallbackResponse;
    }

    @Override
    public Map<String, Object> createActivity(Map<String, Object> activity) {
        Map<String, Object> fallbackResponse = new HashMap<>();
        fallbackResponse.put("id", -1);
        fallbackResponse.put("title", activity.getOrDefault("title", "未知活动"));
        fallbackResponse.put("status", "失败");
        fallbackResponse.put("message", "校园活动服务暂时不可用，无法创建活动，请稍后再试");
        fallbackResponse.put("isFallback", true);
        return fallbackResponse;
    }

    @Override
    public Map<String, Object> updateActivity(Long id, Map<String, Object> activity) {
        Map<String, Object> fallbackResponse = new HashMap<>();
        fallbackResponse.put("id", id);
        fallbackResponse.put("title", activity.getOrDefault("title", "未知活动"));
        fallbackResponse.put("status", "失败");
        fallbackResponse.put("message", "校园活动服务暂时不可用，无法更新活动，请稍后再试");
        fallbackResponse.put("isFallback", true);
        return fallbackResponse;
    }

    @Override
    public List<Map<String, Object>> getActivityCategories() {
        List<Map<String, Object>> fallbackList = new ArrayList<>();
        Map<String, Object> fallbackResponse = new HashMap<>();
        fallbackResponse.put("id", -1);
        fallbackResponse.put("name", "未知类别");
        fallbackResponse.put("description", "活动类别信息暂时无法获取");
        fallbackResponse.put("status", "服务不可用");
        fallbackResponse.put("message", "校园活动服务暂时不可用，请稍后再试");
        fallbackResponse.put("isFallback", true);
        fallbackList.add(fallbackResponse);
        return fallbackList;
    }

    @Override
    public Map<String, Object> getHealthStatus() {
        Map<String, Object> fallbackResponse = new HashMap<>();
        fallbackResponse.put("status", "DOWN");
        fallbackResponse.put("message", "校园活动服务健康检查失败");
        fallbackResponse.put("timestamp", System.currentTimeMillis());
        fallbackResponse.put("isFallback", true);
        return fallbackResponse;
    }
} 